import re

fr = open('result.txt','r',encoding = 'utf-8')
fw = open('术语识别正确率召回率.txt','w',encoding = 'utf-8')

f1 = fr.readlines()

m = 0
c = 0
#计算出答案中实体的数目
for line in f1:
    if line == '\n':
        continue
    line = line.strip().split()
    #print(len(line))
    if line[2] == 'tmS' or line[2] == 'tmE':
        m += 1
    
#print(m,c)

str1 = ''
str2 = ''

for line in f1:
    if line == '\n':
        continue
    line = line.strip().split()
    str1 += line[3]
    if line[2] == line[3]:
        str2 += line[3]

p1 = re.compile(r'tmS')
p2 = re.compile(r'tmB(tmI)*tmE')

l1 = p1.findall(str1)
l2 = p2.findall(str1)

l3 = p1.findall(str2)
l4 = p2.findall(str2)

#print(len(l1),len(l2),len(l3),len(l4))
m1 = len(l1) + len(l2)
m2 = len(l3) + len(l4)

print(m,m1,m2)
p = m2/m1
r = m2/m
f = 2*p*r/(p+r)

s = 0
s1 = 0
for line in f1:
    if line == '\n':
        continue
    line = line.strip().split()
    if line[2] == line[3]:
        s += 1
    s1 += 1
Accuracy = s/s1
    
fw.write(str(m)+' '+str(m1)+' '+str(m2)+'\n'+'Accuracy : '+str(Accuracy)+'\n'+
         'precison : '+str(p)+' '+'recall : '+str(r)+' '+
         'F : '+str(f)+'\n')    

fr.close()
fw.close()
print('ok')
